package thread;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class SyncDemo4 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        Thread t1 = new Thread(){
          public void run(){
              for (int i = 0; i < 1000; i++) {
                  list.add("i");
              }
          }
        };
        Thread t2 = new Thread(){
            @Override
            public void run() {
                for (int i = 0; i < 1000; i++) {
                    list.add("b");
                }
            }
        };
        t1.start();
        t2.start();
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(list.size());
    }
}
